package shiqi.ProxyPattern.springAop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
//InvocationHandler代理实例需要实现的接口，为什么不是实现共同接口？
public class DynamicProxy implements InvocationHandler {

    private Object object;

    public DynamicProxy() {}

    public DynamicProxy(Object object) {
        this.object = object;
    }

    //proxy代表代理类，method代表需要代理的方法，args代表代理方法发入参实现invoke，调用真实主题类的方法
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        preRequest();
        method.invoke(object,args);
        postRequest();
        return null;
    }

    public void preRequest() {
        System.out.println("调用之前");
    }

    public void postRequest() {
        System.out.println("调用之后");
    }
}
